﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;

namespace Barbar.MapReport.Common {
  public class SerializedUnit : IFormattable {
    private double m_Value;
    private UnitType m_UnitType;

    public double Value {
      get { return m_Value; }
      set { m_Value = value; }
    }

    public UnitType UnitType {
      get { return m_UnitType; }
      set { m_UnitType = value; }
    }

    public SerializedUnit() {
    }

    public SerializedUnit(int pixels)
      : this(pixels, UnitType.Pixel) {
    }

    public SerializedUnit(double value, UnitType unitType) {
      m_Value = value;
      m_UnitType = unitType;
    }

    public static implicit operator Unit(SerializedUnit serializedUnit) {
      return new Unit(serializedUnit.Value, serializedUnit.UnitType);
    }

    public override string ToString() {
      Unit unit = this;
      return unit.ToString();
    }


    #region IFormattable Members

    public string ToString(string format, IFormatProvider formatProvider) {
      Unit unit = this;
      return unit.ToString();
    }

    #endregion
  }
}
